home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import re
- import posixpath
- from checkbox.lib.cache import cache
- from checkbox.lib.conversion import string_to_type
- from checkbox.properties import Path, String
- from checkbox.registries.command import CommandRegistry
- from checkbox.registries.data import DataRegistry
-
- class SourceRegistry(DataRegistry):
-
- def items(self):
- items = []
- lines = []
- id = None
- depth = None
- for line in self.split('\n'):
- if not line:
- continue
-
- match = re.match('(\\s+(\\/)?)(.+)', line)
- if not match:
- lines[-1] += line
- continue
-
- space = len(match.group(1).rstrip('/'))
- if depth is None:
- depth = space
-
- if space > depth:
- lines.append(line)
- continue
- if match.group(2) is not None:
- if id is not None:
- value = SourceRegistry('\n'.join(lines))
- lines = []
- items.append((id, value))
-
- id = match.group(3).split('/')[-1].rstrip(':')
- continue
- (key, value) = match.group(3).split(' = ', 1)
- if value == '(no value set)':
- value = None
- else:
- match = re.match('\\[([^\\]]*)\\]', value)
- if match:
- list_string = match.group(1)
- if len(list_string):
- value = list_string.split(',')
- else:
- value = []
- else:
- value = string_to_type(value)
- items.append((key, value))
-
- if lines:
- value = SourceRegistry('\n'.join(lines))
- items.append((id, value))
-
- return items
-
-
-
- class GconfRegistry(CommandRegistry):
- '''Registry for gconf information.
-
- Each item contained in this registry consists of the udi as key and
- the corresponding device registry as value.
- '''
- source = Path(default = '~/.gconf')
- command = String(default = 'gconftool-2 -R / --direct --config-source xml:readwrite:$source')
-
- def __init__(self, *args, **kwargs):
- super(GconfRegistry, self).__init__(*args, **kwargs)
- source = posixpath.expanduser(self.source)
- self.command = self.command.replace('$source', source)
-
-
- def items(self):
- items = []
- key = None
- lines = []
- for line in self.split('\n'):
- if line.startswith(' /'):
- if lines:
- value = SourceRegistry('\n'.join(lines))
- items.append((key, value))
-
- key = line.strip().lstrip('/').rstrip(':')
- continue
- if line:
- lines.append(line)
- continue
-
- if lines:
- value = SourceRegistry('\n'.join(lines))
- items.append((key, value))
-
- return items
-
- items = cache(items)
-
- factory = GconfRegistry
-